package com.gistmap.sideline.util;

import com.gistmap.sideline.entity.Participate;
import com.gistmap.sideline.entity.Partner;
import com.gistmap.sideline.entity.Task;
import com.gistmap.sideline.entity.User;
import com.gistmap.sideline.payload.ParticipateResponse;
import com.gistmap.sideline.payload.TaskResponse;
import com.gistmap.sideline.payload.UserResponse;

import java.util.List;
import java.util.stream.Collectors;

public class ModelMapper {

    public static TaskResponse mapTaskToTaskResponse(Task task, List<Participate> participates, List<Partner> partners){
        TaskResponse taskResponse = new TaskResponse();
        taskResponse.setId(task.getId());
        taskResponse.setStatus(task.getStatus());
        taskResponse.setContent(task.getContent());
        taskResponse.setTitle(task.getTitle());
        List<ParticipateResponse> participateResponses = participates.stream()
                .map(participate -> mapParticipateToParticipateResponse(participate))
                .collect(Collectors.toList());
        taskResponse.setParticipates(participateResponses);
        taskResponse.setJoinCount(participateResponses.size());
        return taskResponse;

    }

    public static UserResponse mapUserToUserResponse(User user){
        UserResponse userResponse = new UserResponse();
        userResponse.setId(user.getId());
        userResponse.setEmail(user.getEmail());
        userResponse.setName(user.getName());
        return userResponse;
    }

    public static ParticipateResponse mapParticipateToParticipateResponse(Participate participate){
        ParticipateResponse participateResponse = new ParticipateResponse();
        participateResponse.setId(participate.getId());
        participateResponse.setContent(participate.getContent());
        participateResponse.setUser(mapUserToUserResponse(participate.getUser()));
        participateResponse.setCreatedTime(participate.getCreatedAt());
        return participateResponse;
    }
}
